package com.example.database;

import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.util.Log;

public class LichkhamTB {
    DatabaseHelp databasehelp;
	public LichkhamTB(Context context) {
        databasehelp = new DatabaseHelp(context);
	}

	// private DatabaseHelp dbHelper;
	public final static String CLASS_TABLE = "tbLichkham";
	public final static String CLASS_MALICHKHAM = "maLichkham";
    public final static String CLASS_MACHUYENKHOA = "maChuyenkhoa";
	public final static String CLASS_MABACSI = "maBacsi";
	public final static String CLASS_NGAY = "Ngay";
	public final static String CLASS_GIO = "Gio";
    public final static String CLASS_TRANGTHAI = "Trangthai";
	public static String ten ="abc";
	

	public Cursor getInforLichkham(String query) {

		Cursor cursor = databasehelp.selectQuery(query);
		if (cursor != null)
			cursor.moveToFirst();
		return cursor;
	}
	public void insertInforLichkham(String maChuyenkhoa,String maBacsi,String Ngay,String Gio,String Trangthai) {
		ContentValues value = new ContentValues();
		value.put(CLASS_MACHUYENKHOA, maChuyenkhoa);
		value.put(CLASS_MABACSI, maBacsi);
        value.put(CLASS_NGAY, Ngay);
        value.put(CLASS_GIO, Gio);
        value.put(CLASS_TRANGTHAI, Trangthai);
		long kq = databasehelp.insert_table(CLASS_TABLE, value);
		if(kq == -1)
		{
			Log.e("SQL", "Loi Insert");
		}
		else
		{
			Log.e("SQL", "Thanh cong");
		}
	}
	public void updateInforLichkham(String maChuyenkhoa,String maBacsi,String Ngay,String Gio,String Trangthai, String maLichkham) {
		ContentValues values = new ContentValues();
        values.put(CLASS_MACHUYENKHOA, maChuyenkhoa);
        values.put(CLASS_MABACSI, maBacsi);
        values.put(CLASS_NGAY, Ngay);
        values.put(CLASS_GIO, Gio);
        values.put(CLASS_TRANGTHAI, Trangthai);
		long kq = databasehelp.update_table(CLASS_TABLE, values, maLichkham, CLASS_MALICHKHAM);
		if(kq < 0)
		{
			Log.e("SQL", "Loi Insert");
		}
		else
		{
			Log.e("SQL", "Thanh cong");
		}
	}
	public long updateStatusLichkham(String maLichkham, String status) {
		ContentValues values = new ContentValues();
        values.put(CLASS_TRANGTHAI, status);
		long kq = databasehelp.update_table(CLASS_TABLE, values, maLichkham, CLASS_MALICHKHAM);
		if(kq < 0)
		{
			Log.e("SQL", "Loi Insert");
		}
		else
		{
			Log.e("SQL", "Thanh cong");
		}
		return kq;
	}
	public void updateMulInforLichkham(String maChuyenkhoa,String maBacsi,String Ngay,String Gio,String Trangthai, String maLichkham) {
		ContentValues values = new ContentValues();
        values.put(CLASS_MACHUYENKHOA, maChuyenkhoa);
        values.put(CLASS_MABACSI, maBacsi);
        values.put(CLASS_NGAY, Ngay);
        values.put(CLASS_GIO, Gio);
        values.put(CLASS_TRANGTHAI, Trangthai);
		long kq = databasehelp.update_mul_table(CLASS_TABLE, values, CLASS_MALICHKHAM+"=? AND " +CLASS_MACHUYENKHOA+"=?" , new String[]{maLichkham,maChuyenkhoa});
		if(kq < 0)
		{
			Log.e("SQL", "Loi Insert");
		}
		else
		{
			Log.e("SQL", "Thanh cong");
		}
	}
	public void deleteInforLichkham(String maLichkham) {
		long kq = databasehelp.delete_table(CLASS_TABLE,CLASS_MALICHKHAM,maLichkham );
		if(kq < 0)
		{
			Log.e("SQL", "Loi Insert");
		}
		else
		{
			Log.e("SQL", "Thanh cong");
		}
	}
}
